import type { DynamicProps } from '/#/utils';
import type { BasicTableProps, BasicColumn } from '/@/components/Table/src/types/table';
import { FormProps } from '/@/components/Table';
import { searchSchemas } from './searchData';
import { queryofflog } from '/@/api/sys/gateway/gateway';
type Props = Partial<DynamicProps<BasicTableProps>>;
import moment from 'moment';
// 列配置
const tableColumns: BasicColumn[] = [
  {
    title: '设备名称',
    dataIndex: 'device_name',
    key: 'device_name',
    width: 60,
    sorter: true,
  },
  {
    title: '离线时间',
    dataIndex: 'off_time',
    width: 130,
  },
  {
    title: '恢复时间',
    dataIndex: 'on_time',
    width: 100,
  },
  {
    title: '离线时长(分钟)',
    dataIndex: 'restore_time_minutes',
    width: 100,
    key: 'restore_time_minutes',
    sorter: true,
  },
];
export const formConfig: Partial<FormProps> = {
  labelWidth: 80,
  schemas: searchSchemas,
  actionColOptions: {
    span: 5,
    style: { textAlign: 'left', marginLeft: '10px' },
  },
};
export const tableConfig: Props = {
  api: queryofflog,
  columns: tableColumns,
  useSearchForm: true,
  formConfig: formConfig,
  clickToRowSelect: false,
  showTableSetting: true,
  canColDrag: true,
  tableSetting: { fullScreen: true },
  showIndexColumn: false,
  rowKey: 'id',
  bordered: true,
  beforeFetch: (formModel) => {
    if (formModel.time) {
      formModel.start_time =
        formModel.time.length == 0
          ? undefined
          : moment(formModel.time[0]).format('YYYY-MM-DD HH:mm:ss');
      formModel.end_time =
        formModel.time.length == 0
          ? undefined
          : moment(formModel.time[1]).format('YYYY-MM-DD HH:mm:ss');
    }
  },
  fetchSetting: {
    //配置数据data名称
    listField: 'list',
    totalField: 'total',
    sizeField: 'page_size',
  },
};
